package org.apache.lucene.ocean.util;

import java.util.concurrent.locks.ReentrantLock;

/**
 * Sequence for long values.  Allows the value to be set.
 *
 */
public class LongSequence {
	private long value;
	private int increment;
	private ReentrantLock lock = new ReentrantLock();

	public LongSequence(long value, int increment) {
		this.value = value;
		this.increment = increment;
	}
	
	public long get() {
		lock.lock();
		try {
			return value;
		} finally {
			lock.unlock();
		}
	}
	
	public void set(long i) {
		lock.lock();
		try {
			value = i;
		} finally {
			lock.unlock();
		}
	}
	
	public long getAndIncrement() {
		lock.lock();
		try {
			long v = value;
			value += increment;
			return v;
		} finally {
			lock.unlock();
		}
	}
}
